package com.ywy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ywy.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 首页Controller
 *
 * @author ywy
 * @date 2021/12/24 13:41
 */
@Controller
public class IndexController extends BaseController {
    @Autowired
    private PostService postService;

    @RequestMapping({"", "/", "/index"})
    public String index() {
        // 默认分类
        req.setAttribute("currentCategoryId", 0);
        int typeId = ServletRequestUtils.getIntParameter(req, "typeId", 0);
        int orderId = ServletRequestUtils.getIntParameter(req, "orderId", 0);
        req.setAttribute("typeId", typeId);
        req.setAttribute("orderId", orderId);
        // 分页查询文章信息
        Integer level = ServletRequestUtils.getIntParameter(req, "level", -1);
        String order = ServletRequestUtils.getStringParameter(req, "order", "create_time");
        IPage results = postService.listByPage(getPage(), null, null, level, null, order);
        req.setAttribute("pageData", results);
        return "index";
    }
}
